package com.example.system.controller.User;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.SaTokenInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.aop.TestAll;
import com.example.common.pojo.CommonResult;
import com.example.common.pojo.PageResult;
import com.example.system.controller.User.VO.UserLoginReqVO;
import com.example.system.controller.User.VO.UserPageParamReqVO;
import com.example.system.controller.User.VO.UserRespVO;
import com.example.system.service.User.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("")
public class UserController {
    @Resource
    UserService userService;

    @GetMapping("/user/login")
    public CommonResult<String> doLogin(@Validated UserLoginReqVO userLoginReqVO) {
        return userService.doLogin(userLoginReqVO);
    }
    @GetMapping("/user/loginOut")
    @SaCheckPermission("user:page")
    public CommonResult<String> doLogin() {
        return userService.doLoginOut();
    }
    @GetMapping("/user/page")
    @TestAll
    @SaCheckPermission("user:page")
    public CommonResult<PageResult<UserRespVO>> getPage(@Validated UserPageParamReqVO userPageParamReqVO) {
        return CommonResult.data(userService.getUserPage(userPageParamReqVO));
    }

    @GetMapping("/user/list")
    public CommonResult<List<UserRespVO>> getList() {
        return CommonResult.data(userService.getUserList());
    }
}
